So far, we've simply added and
committed all our changes. However, we've
actually committed those changes to something
called a branch. As mentioned before, this branch is called master by default. Now, let's say that
a new developer joins the project and
wants to add a new story. We don't want
developers to directly make changes to our
production code, but instead give them a
separate version where they can change code and commit to until their work is done. In the meantime, we can keep on working on
our own branch. Only after their entire
work is done and tested, we want to get the new code
into the production code. What we're actually
saying here is that we don't want to always
work on the master branch, but keep our project
version using branches. A branch is basically a
pointer to the last commit. If you're working
on a new feature, you might work on
a branch called feature forward slash sign up, and only once that feature has been finished and
entirely tested, we want to get all those
changes into the master branch. First, let's create
a new branch. We can do so by running the git checkout B command
with the name of the branch. Say that the developer
is called Sarah, and we just create
a Sarah branch. To see a list of all our branches and the branch
that we're currently on, we execute the git
branch command. Currently, we have two
branches, Master and Sarah. In total, we've made one
commit initial commit. They both point to that commit. As stated before,
branches are actually nothing more than pointers
to a certain commit. Now, let's say that Sarah adds a new story and commits
this to the Sarah branch. This commit gets added
to the Sara branch, but not to the master branch. The master branch is now one commit behind
the Sarah branch. Let's say that the
team is growing, and you just hired
a new developer. This developer called Max wants
to write the third story. Max is currently still checked
out on the master branch, but to keep things clean, Max also creates his
own branch called Max. Max writes the third story and commits this
to his Max branch. The Sarah and Master branch
don't have this change yet. Only Max's branch
has this change. Here are some useful
commands that you can use when you're
working with branches. In order to create a new branch, you can run the
Git branch command with the name of the new branch. You can switch branches with
the git checkout command, followed by the name of the branch to which
you want to switch. To create a new branch and immediately switch
to this new branch, you can run the Git
checkout command. This command combines
the Git branch and Git checkout
command together. To delete a branch, run the Git branch D command. The D flag stands for delete. To list all the branches
that you currently have, you can run the Git
branch command. Now that we've talked
about branches, it's important to
know what a head is. You might see the reference to head in quite a few places. The head is where you are right now in the Git repository. The head points to
the last commit in the branch that
you're currently on. When you switch branches, the head moves with you.